#!/usr/bin/python
# script for auto save

import os
import time

#1. file to save
src = ['/home/wzq/workspace/test/python1/src']

#2. back file store dir
dstDir = '/home/wzq/workspace/test/python1/'+time.strftime('%Y-%m-%d')
if not os.path.exists(dstDir):
	os.mkdir(dstDir)
	print 'mkdir success'
now = time.strftime('%H%M%S')
#2.2 add comment
comment = raw_input('Enter a comment:')
#3. bakc file name
if len(comment) ==0:
	dstFile = dstDir+os.sep+now+'.zip'
else:
	dstFile = dstDir+os.sep+now+'_'+\
	comment.replace(' ','_')+'.zip'

#4. zip command
zipCmd = "zip -qr '%s' %s"%(dstFile,' '.join(src));

#5. run the backup
if os.system(zipCmd)==0:
	print 'success',dstFile
else:
	print 'backup failed'